from flask_wtf import CSRFProtect
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap5
from flask_login import LoginManager
from sqlalchemy import select

csrf = CSRFProtect()
db = SQLAlchemy()
bootstrap = Bootstrap5()
login_manager = LoginManager()


@login_manager.user_loader
def load_user(user_id):  # user_id 是flask-login的会话中存储的用户ID
    from flaskLogin.models import Account
    user = db.session.execute(select(Account).filter_by(alternative_id=user_id)).scalar_one_or_none()
    return user


login_manager.login_view = 'sign.login'
login_manager.login_message_category = 'warning'
login_manager.login_message = '请刷新页面，并重新登录.'
